"use strict";
layui.use(["okUtils", "table", "countUp", "okMock"], function () {
    var countUp = layui.countUp;
    var table = layui.table;
    var okUtils = layui.okUtils;
    var okMock = layui.okMock;
    var $ = layui.jquery;
    var ip = "http://localhost"; //后台ip
    var port = ":9014"; //端口
        
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
        return unescape(r[2]);
        }
        return null;
    };

    var userId = getQueryString("id"); 
    /**
     * 最新动态分页查询
     */
    function messagePage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/message/searchByPage',
            elem: '#userData',
            height: 340,
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "date", title: "日期", width: 180},
                {field: "operator", title: "操作人", width: 100},
                {field: "action", title: "动作", width: 150},
                {field: "object", title: "对象", width: 80},
                {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(userdata)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.object+"的"+data.objectName+"页面");
            }
        });
    }

    /**
     * 项目分页查询
     */
    function projectPage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/project/searchByPage',
            elem: '#project',
            height: 340,
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "name", title: "项目名称", width: 180,style: "cursor:pointer;color:blue"},
                {field: "code", title: "项目代号", width: 100},
                {field: "finishTime", title: "结束日期", width: 200},
                {field: "state", title: "状态", width: 100,templet: function(d){
                        if(d.state == 1){
                            return '<div>未开始</div>';
                        }else if(d.state == 2){
                            return '<div style="color:red;">进行中</div>';
                        }else if(d.state == 3){
                            return '<div>已挂起</div>';
                        }else if(d.state == 4){
                            return '<div>已完成</div>';
                        }else if(d.state == 5){
                            return '<div>已关闭</div>';
                        }
                 }}
                // {field: "object", title: "对象", width: 80},
                // {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(project)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.name+"的页面");
            }
        });
    }
    
    //未关闭产品分页查询
    function productPage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/product/searchByPage',
            elem: '#product',
            height: 340,
            where: {state: 1},
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "name", title: "产品名称", width: 180,style: "cursor:pointer;color:blue"},
                {field: "code", title: "产品代号", width: 100},
                {field: "productHeaderName", title: "产品负责人", width: 100},
                {field: "testHeaderName", title: "测试负责人", width: 100},
                {field: "publishHeaderName", title: "发布负责人", width: 100},
                {field: "state", title: "状态", width: 100,templet: function(d){
                        if(d.state == 1){
                            return '<div>未开始</div>';
                        }else if(d.state == 2){
                            return '<div style="color:red;">进行中</div>';
                        }else if(d.state == 3){
                            return '<div>已挂起</div>';
                        }else if(d.state == 4){
                            return '<div>已完成</div>';
                        }else if(d.state == 5){
                            return '<div>已关闭</div>';
                        }
                 }}
                // {field: "object", title: "对象", width: 80},
                // {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(product)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.name+"的页面");
            }
        });
    }

    //指派给我的任务分页查询
    function taskPage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/task/searchByPage',
            elem: '#task',
            height: 340,
            where: {appointer: userId,closer: 0},
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "priority", title: "优先级", width: 80,templet: function(d){
                        if(d.priority == 1){
                            return '<div style="color:red;">紧急</div>';
                        }else if(d.priority == 2){
                            return '<div style="color:orange;">严重</div>';
                        }else if(d.priority == 3){
                            return '<div style="color:yellow;">重视</div>';
                        }else if(d.priority == 4){
                            return '<div style="color:blue;">常规</div>';
                        }else if(d.priority == 0){
                            return '<div>未定义</div>';
                        }
                }},
                {field: "name", title: "任务名称", width: 180,style: "cursor:pointer;color:blue"},
                {field: "finishTime", title: "截止时间", width: 180},
                {field: "state", title: "状态", width: 100,templet: function(d){
                        if(d.state == 1){
                            return '<div>未开始</div>';
                        }else if(d.state == 2){
                            return '<div style="color:red;">进行中</div>';
                        }else if(d.state == 3){
                            return '<div>已挂起</div>';
                        }else if(d.state == 4){
                            return '<div>已完成</div>';
                        }else if(d.state == 5){
                            return '<div>已关闭</div>';
                        }
                 }}
                // {field: "object", title: "对象", width: 80},
                // {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(task)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.name+"的页面");
            }
        });
    }

    //指派给我的Bug分页查询
    function bugPage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/bug/searchByPage',
            elem: '#bug',
            height: 340,
            where: {pointer: userId,closer: 0},
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "priority", title: "优先级", width: 80,templet: function(d){
                        if(d.priority == 1){
                            return '<div style="color:red;">紧急</div>';
                        }else if(d.priority == 2){
                            return '<div style="color:orange;">严重</div>';
                        }else if(d.priority == 3){
                            return '<div style="color:yellow;">重视</div>';
                        }else if(d.priority == 4){
                            return '<div style="color:blue;">常规</div>';
                        }else if(d.priority == 0){
                            return '<div>未定义</div>';
                        }
                }},
                {field: "name", title: "Bug名称", width: 210,style: "cursor:pointer;color:blue"},
                {field: "severity", title: "级别", width: 80,templet: function(d){
                        if(d.severity == 1){
                            return '<div style="color:red;">紧急</div>';
                        }else if(d.severity == 2){
                            return '<div style="color:orange;">严重</div>';
                        }else if(d.severity == 3){
                            return '<div style="color:yellow;">重视</div>';
                        }else if(d.severity == 4){
                            return '<div style="color:blue;">常规</div>';
                        }else if(d.severity == 0){
                            return '<div>未定义</div>';
                        }
                 }},
                {field: "creatorName", title: "Bug创建者", width: 100},
                {field: "state", title: "状态", width: 100,templet: function(d){
                        if(d.state == 1){
                            return '<div>未开始</div>';
                        }else if(d.state == 2){
                            return '<div style="color:red;">进行中</div>';
                        }else if(d.state == 3){
                            return '<div>已挂起</div>';
                        }else if(d.state == 4){
                            return '<div>已完成</div>';
                        }else if(d.state == 5){
                            return '<div>已关闭</div>';
                        }
                 }}
                // {field: "object", title: "对象", width: 80},
                // {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(bug)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.name+"的页面");
            }
        });
    }

    //指派给我的需求分页查询
    function demandPage() {
        table.render({
            method: "get",
            url: 'http://localhost:9014/demand/searchByPage',
            elem: '#demand',
            height: 340,
            where: {approver: userId},
            page: true,
            skin: 'nob',
            cols: [[
                {field: "id", title: "ID", width: 50},
                {field: "priority", title: "优先级", width: 80,templet: function(d){
                        if(d.priority == 1){
                            return '<div style="color:red;">紧急</div>';
                        }else if(d.priority == 2){
                            return '<div style="color:orange;">严重</div>';
                        }else if(d.priority == 3){
                            return '<div style="color:yellow;">重视</div>';
                        }else if(d.priority == 4){
                            return '<div style="color:blue;">常规</div>';
                        }else if(d.priority == 0){
                            return '<div>未定义</div>';
                        }
                }},
                {field: "name", title: "需求名称", width: 180,style: "cursor:pointer;color:blue"},
                {field: "spendTime", title: "预计时间", width: 180},
                {field: "state", title: "状态", width: 100,templet: function(d){
                        if(d.state == 1){
                            return '<div>未开始</div>';
                        }else if(d.state == 2){
                            return '<div style="color:red;">进行中</div>';
                        }else if(d.state == 3){
                            return '<div>已挂起</div>';
                        }else if(d.state == 4){
                            return '<div>已完成</div>';
                        }else if(d.state == 5){
                            return '<div>已关闭</div>';
                        }
                 }}
                // {field: "object", title: "对象", width: 80},
                // {field: "objectName", title: "对象名称", width: 250,style: "cursor:pointer;color:blue"}
            ]],
            parseData: function (res) {
                return {
                    "code": 0,
                    "count": res.records,
                    "data": res.data
                }
            }
        });

        table.on('row(product)', function(obj){
            console.log(obj.data) //得到当前行数据
            var data = obj.data;
            if(data.object != "系统"){
                alert("跳转"+data.name+"的页面");
            }
        });
    }
    messagePage();
    projectPage();
    productPage();
    taskPage();
    bugPage();
    demandPage();
});


